package edu.jmu.action.schedule;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import edu.jmu.action.BaseAction;
import edu.jmu.bean.PageView;
import edu.jmu.bean.schedule.Meeting;
import edu.jmu.bean.schedule.Schedule;
import edu.jmu.service.schedule.ScheduleService;
import edu.jmu.utils.WebUtil;

@Controller
@Scope(value="prototype")
public class ScheduleManageAction extends BaseAction<Schedule>{
	private static final long serialVersionUID = -1304518683866034281L;
	 
	@Resource
	private ScheduleService scheduleService;
	
	private Schedule schedule;//时间
	private int meetingType;//会议类型
	private String beginTime;//开始时间
	private String endTime;//结束时间
	private String address;//地址
	private String content;//内容
	
	public String addSchedule(){
		if(meetingType == 0){
			schedule.setMeeting(Meeting.COMPANY);
		}else if(meetingType == 1){
			schedule.setMeeting(Meeting.BRANCH);
		}else{
			schedule.setMeeting(Meeting.DEPART);
		}
		
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");		
		try {
			schedule.setBeginTime(dateFormat.parse(beginTime));
			schedule.setEndTime(dateFormat.parse(endTime));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		schedule.setAddress(address);
		schedule.setContent(content);
		schedule.setCreateUser(WebUtil.getUser());
		scheduleService.save(schedule);
		return SUCCESS;
	}	
	
	public String listSchedule(){
		pageView  = new PageView<Schedule>(maxresult,currentpage);
		pageView.setQueryResult(scheduleService.getScrollData(pageView.getFirstResult(), pageView.getMaxresult()));//分页
		return SUCCESS;
	}
	
	public void setSchedule(Schedule schedule) {
		this.schedule = schedule;
	}
	public void setMeetingType(int meetingType) {
		this.meetingType = meetingType;
	}
	public void setBeginTime(String beginTime) {
		this.beginTime = beginTime;
	}
	public void setEndTime(String endTime) {
		this.endTime = endTime;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public void setContent(String content) {
		this.content = content;
	}

	
}
